package com.qyer.lxp.common.framework.convert;

import com.qyer.lxp.common.framework.httpclient.HttpClientUtil;
import com.qyer.lxp.common.framework.util.QyerUtils;

/**
 *
 * xml序列化成java对象数据类
 * Created by jiangping on 16/5/11.
 */
public class TransformSession {

    /**
     * 正常xml查询接口类
     * @param method    要调用接口或方法名称
     * @param param    调用接口的参数
     * @param clazz    返回类型
     * @return  返回java对象
     * @throws Exception
     */
    public static Object selectOne(String method,Object param,Class<?> clazz) throws Exception{
        String params = "";
        if(null != param){
            params = XmlHelper.objectToXML(param.getClass(),param);
        }
        String xml = HttpClientUtil.requestPost(method,params);
        xml = HttpClientUtil.removeNormalHeader(xml);
        if(QyerUtils.isEmpty(xml)){
            return null;
        }
        return XmlHelper.xmlToObject(clazz,xml);
    }

    /**
     * 正常xml查询接口类
     * @param method    要调用接口或方法名称
     * @param param    调用接口的参数
     * @param clazz    返回类型
     * @return  返回java对象
     * @throws Exception
     */
    public static Object selectExtraOne(String method,Object param,Class<?> clazz) throws Exception{
        String params = "";
        if(null != param){
            params = XmlHelper.objectToXML(param.getClass(),param);
        }
        String xml = HttpClientUtil.requestPost(method,params);
        xml = HttpClientUtil.removeExtraHeader(xml,clazz.getSimpleName());
        if(QyerUtils.isEmpty(xml)){
            return null;
        }
        return XmlHelper.xmlToObject(clazz,xml);
    }
}
